<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no" />
		<title>愉直播</title>
		<link rel="stylesheet" type="text/css" href="../c/aui.css" />
		<style>
			body,
		html {
			height: 100%;
		}

		body {
			background-color: transparent;
			/*background-color: #000;*/
		}

		.by {
			width: 100%;
			height: 100%;
			background: url('../i/login.png') center center !important;
			background-repeat: no-repeat !important;
			background-position: center !important;
			background-size: cover !important;
			-webkit-filter: blur(0.1rem);
		}

		.img {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			bottom: 0;
			text-align: center;
		}

		img {
			display: inline-block;
		}
	</style>
	</head>

	<body>
		
		<div class="by"></div>
	</body>
	<script type="text/javascript" src="../j/api.js"></script>
	<script type="text/javascript">
		var _root = false,
			alivcLivePlayer, oxPlayer
		apiready = function() {
			_user = _getPrefs('_user');
			oxPlayer = api.require('oxPlayer');
			if (api.pageParam['url']) {
				// alivcLivePlayer = api.require('alivcLivePlayer');
			}
			// 判断返回键
			api.addEventListener({
				name: 'keyback'
			}, function(ret, err) {});
			// console.log(api.pageParam['img_l'])
			if (api.pageParam['url']) {
				$api.css($api.dom('.by'), 'background:url(' + api.pageParam['img_r'] + ') center center !important')
			} else {
				$api.css($api.dom('.by'), 'background:url(' + _img(api.pageParam['img_r'], api.winWidth, api.winHeight) +
					') center center !important')
			}
			api.setFullScreen({
				fullScreen: true
			});
			// api.showProgress({
			// 	title : '',
			// 	text : '',
			// 	modal : true,
			// 	animationType : 'zoom',
			// });
			// 回到屏幕
			api.addEventListener({
				name: 'viewappear'
			}, function(ret, err) {
				api.execScript({
					script: 'oxPlayer.start();'
				});
				api.setFullScreen({
					fullScreen: true
				});
				if (_root) {
					if (api.pageParam['uid'] == _user.id) {
						api.execScript({
							frameName: 'zhibo_view_frm_1',
							script: 'zhibo_edit(1);'
						});
					}
				}
				_root = true;
			});
			// 离开屏幕
			api.addEventListener({
				name: 'viewdisappear'
			}, function(ret, err) {
				api.execScript({
					script: 'oxPlayer.pause();'
				});
				api.setFullScreen({
					fullScreen: false
				});
				if (api.pageParam['uid'] == _user.id) {
					api.execScript({
						frameName: 'zhibo_view_frm_1',
						script: 'zhibo_edit();'
					});
				}
			});
			//应用进入后台事件
			api.addEventListener({
				name: 'pause'
			}, function(ret, err) {

				api.setFullScreen({
					fullScreen: false
				});
				if (api.pageParam['uid'] == _user.id) {
					api.execScript({
						frameName: 'zhibo_view_frm_1',
						script: 'zhibo_edit(1);'
					});
				}
			});
			// 应用从后台回到前台事件
			api.addEventListener({
				name: 'resume'
			}, function(ret, err) {

				api.setFullScreen({
					fullScreen: true
				});
				if (api.pageParam['uid'] == _user.id) {
					api.execScript({
						frameName: 'zhibo_view_frm_1',
						script: 'zhibo_edit(1);'
					});
				}
			});
			win();
		}

		function win() {
			if (api.pageParam['uid'] == _user.id) {
				var password = api.pageParam['anchorPwd'];
			} else {
				var password = api.pageParam['userPwd'];
			}
			var nickname = api.pageParam['nickname'];
			var session = {
				roomId: api.pageParam['roomId'],
				password: password,
				nickname: nickname
			};
			var core = api.require('gotyeLiveCore');
			core.setDebugLogEnabled({
				enabled: true
			});
			//  console.log(JSON.stringify(api.pageParam))
			core.authRoomSession(session, function(ret, err) {
				if (ret) {
					var url = api.pageParam['url'];
					var img = api.pageParam['img_r'];
					if (!url) {
						url = _getPrefs('_config').zhibo.url + api.pageParam['roomId'];
						var img = _img(api.pageParam['img_r'], api.winWidth, api.winHeight);
					}
					console.log(JSON.stringify(ret))
					if (ret.role != 2) {
						video(url, img);
					}
					// console.log(url)
					// if(url){
					// 	video(url);
					// }
					//		console.log(JSON.stringify(ret))
					var name = 'zhibo_view_frame';
					api.pageParam['ret'] = ret;
					api.openFrame({
						name: name,
						url: _h_w + name + '.html',
						rect: {
							x: 0,
							y: 0,
							w: 'auto',
							h: 'auto'
						},
						bounces: false,
						bgColor: 'rgba(0,0,0,0)',
						vScrollBarEnabled: false,
						hScrollBarEnabled: false,
						pageParam: api.pageParam
					});
				} else {
					_alert("错误：" + JSON.stringify(err), function(ret, err) {
						_close();
					})
					// _loadingCloes();
				}
			});
		}

		function video(url, img) {
			video_open(url, img);
			return;
			var url = 'https://liveplay.guojianglive.com/live/9180_1269777.flv';
			url = 'https://liveplay.guojianglive.com/live/9180_1269777.flv';
			url = 'rtmp://liveplay.guojianglive.com/live/9180_1269777';
			url = 'http://qiniu2.svideo.suxiangw.com/qiniu___a48eeed44a5f033017b7cbbb77167ea1';
			url = 'rtmp://liveplay.guojianglive.com/live/9180_783283'
			url = api.pageParam['url'];
			alivcLivePlayer.initPlayer({
				rect: {
					x: 0,
					y: 0,
					w: api.winWidth,
					h: api.winHeight,
				}
			})
			alivcLivePlayer.setVideoScalingMode({
				scalingMode: 'corp'
			});
			alivcLivePlayer.prepareToPlay({
				url: url
			})
			alivcLivePlayer.play();
		}

		function guanbi() {

		}

		function video_open(url, img) {
			if (_win_name == 1) {
				return _video_open(url, img);
			}
			console.log(url)
			oxPlayer.zbPlay({
				fixedOn: api.frameName,
				rect: {
					x: 0,
					y: 0,
					w: 'auto',
					h: 'auto'
				},
				fixed: true,
				showBack: false, //返回按钮是否显示事件返回code:0滑动返回code:1android有效
				rightSlide: false, //右滑禁止开关  code 12 监听互动x坐标 为正 浮点型
				leftSlide: false, //左滑禁止开关code 12 监听互动x坐标 为负 浮点型
				showDoubleClick: false, //双击红心点赞事件返回code:3
				playBtn: '', //中间播放按钮图片(自定义) 可选 没有则用系统自带
				backgroundColor: '#000000', //视频背景颜色
				// backgroundHolder: 'widget://image/icon_music_cover.png', //视频背景图片
				// avatarHolder: 'widget://image/icon_music_cover.png', //头像背景图片
				marginBottom: 0, //进度条距离底部距离
				styles: [],
				data: {
					userInfo: {
						isFocus: true
					},
					music: {},
					vid: '',
					title: '',
					thumb: api.systemType == 'ios' ? '' : api.pageParam['img_l'],
					url: url
				}
			});
		}
	</script>

</html>
